import React from 'react';

const JsonLd = ({ data }) => {
  return (
    <script
      type="application/ld+json"
      dangerouslySetInnerHTML={{ __html: JSON.stringify(data) }}
    />
  );
};

// 网站结构化数据
export const WebsiteJsonLd = () => {
  const data = {
    "@context": "https://schema.org",
    "@type": "WebSite",
    "name": "技术博客",
    "description": "专业的技术博客，分享前端开发、后端技术、系统架构、DevOps等领域的深度文章和实践经验",
    "url": "https://your-domain.com",
    "author": {
      "@type": "Person",
      "name": "技术博主",
      "url": "https://your-domain.com/about"
    },
    "publisher": {
      "@type": "Organization",
      "name": "技术博客",
      "logo": {
        "@type": "ImageObject",
        "url": "https://your-domain.com/logo.png"
      }
    },
    "potentialAction": {
      "@type": "SearchAction",
      "target": "https://your-domain.com/search?q={search_term_string}",
      "query-input": "required name=search_term_string"
    },
    "inLanguage": "zh-CN"
  };

  return <JsonLd data={data} />;
};

// 博客文章结构化数据
export const BlogPostJsonLd = ({ post }) => {
  const data = {
    "@context": "https://schema.org",
    "@type": "BlogPosting",
    "headline": post.title,
    "description": post.excerpt,
    "image": post.image || "https://your-domain.com/default-blog-image.jpg",
    "url": `https://your-domain.com/blog/${post.id}`,
    "datePublished": post.date,
    "dateModified": post.date,
    "author": {
      "@type": "Person",
      "name": "技术博主",
      "url": "https://your-domain.com/about"
    },
    "publisher": {
      "@type": "Organization",
      "name": "技术博客",
      "logo": {
        "@type": "ImageObject",
        "url": "https://your-domain.com/logo.png"
      }
    },
    "mainEntityOfPage": {
      "@type": "WebPage",
      "@id": `https://your-domain.com/blog/${post.id}`
    },
    "keywords": post.tags,
    "articleSection": "技术",
    "inLanguage": "zh-CN",
    "wordCount": post.content ? post.content.length : 0,
    "timeRequired": post.readTime
  };

  return <JsonLd data={data} />;
};

// 技术文章结构化数据
export const TechArticleJsonLd = ({ note, category }) => {
  const data = {
    "@context": "https://schema.org",
    "@type": "TechArticle",
    "headline": note.title,
    "description": note.excerpt,
    "url": `https://your-domain.com/notes/${category}/${note.id}`,
    "datePublished": note.date,
    "dateModified": note.date,
    "author": {
      "@type": "Person",
      "name": "技术博主",
      "url": "https://your-domain.com/about"
    },
    "publisher": {
      "@type": "Organization",
      "name": "技术博客",
      "logo": {
        "@type": "ImageObject",
        "url": "https://your-domain.com/logo.png"
      }
    },
    "mainEntityOfPage": {
      "@type": "WebPage",
      "@id": `https://your-domain.com/notes/${category}/${note.id}`
    },
    "articleSection": "技术笔记",
    "inLanguage": "zh-CN",
    "proficiencyLevel": "Intermediate",
    "dependencies": category,
    "timeRequired": note.readTime
  };

  return <JsonLd data={data} />;
};

// 面包屑导航结构化数据
export const BreadcrumbJsonLd = ({ items }) => {
  const data = {
    "@context": "https://schema.org",
    "@type": "BreadcrumbList",
    "itemListElement": items.map((item, index) => ({
      "@type": "ListItem",
      "position": index + 1,
      "name": item.name,
      "item": item.url
    }))
  };

  return <JsonLd data={data} />;
};

// 个人信息结构化数据
export const PersonJsonLd = () => {
  const data = {
    "@context": "https://schema.org",
    "@type": "Person",
    "name": "技术博主",
    "jobTitle": "全栈开发者",
    "description": "一名热爱技术的全栈开发者，专注于创造优雅的用户体验和高质量的代码",
    "url": "https://your-domain.com/about",
    "image": "https://your-domain.com/avatar.jpg",
    "sameAs": [
      "https://github.com/yourusername",
      "https://twitter.com/yourusername",
      "https://linkedin.com/in/yourusername"
    ],
    "knowsAbout": [
      "JavaScript",
      "TypeScript", 
      "React",
      "Vue.js",
      "Node.js",
      "Python",
      "Java",
      "Docker",
      "Kubernetes",
      "系统架构",
      "微服务"
    ],
    "alumniOf": {
      "@type": "Organization",
      "name": "某某大学"
    },
    "worksFor": {
      "@type": "Organization",
      "name": "科技公司"
    }
  };

  return <JsonLd data={data} />;
};

export default JsonLd;
